package com.encryption.servlet;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.encryption.service.ca.impl.InitDeptCertInfoImpl;
import com.encryption.service.qrc.impl.DocEncryptHandlerImpl;
import com.encryption.util.TestUseUtil;
import com.log4ic.DocViewer;
import com.log4ic.utils.io.FileUtils;

public class InitializeServletContextListener implements ServletContextListener {
    
	@Override
	public void contextDestroyed(ServletContextEvent event) {
		// TODO Auto-generated method stub
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		// TODO Auto-generated method stub
		try {
//		    if(!AuthUtil.isPass()){
//		        System.exit(-1);
//		        return;
//		    }
			String path = System.getProperty("catalina.home") + "/webapps/Root/file";
			String tempPath = path + "/" + "temp";
			FileUtils.deleteFile(tempPath, false);
			
			boolean isReg = new DocEncryptHandlerImpl().isReg();
			if(isReg == false){
				boolean isTest = TestUseUtil.isTest();
				if(isTest == false){
//					System.exit(-1);
				}
			}
			
			InitDeptCertInfoImpl init = new InitDeptCertInfoImpl();
			init.init();
			
			DocViewer.setInputPath(path);
			DocViewer.setOutputPath(path + "/target");
			DocViewer.initialize();
//			File fileDir = new File(path);
//			
//			OfficeConverter converter = new OfficeConverter();
//			for (String oneFile : fileDir.list()){
//				if(!"swf".equalsIgnoreCase(FileUtils.getFileSuffix(oneFile)))
//					converter.convert(path + "/" + oneFile, path + "/target/" + oneFile + ".pdf");
//			}
//			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
